/*******************************************************************************
 Copyright (c) 2010 Koninklijke Philips N.V.,
 All Rights Reserved.
 
 File name: fsm.h
 Description: Header file for the FSM component
 Project: XXX
 Component name: FSM 
 $LastChangedDate:  $
 $Revision:  $
 $Author:  $
 Lighting GBU CFLi
 
 This source code and any compilation or derivative thereof is the
 proprietary information of Koninklijke Philips N.V.
 and is confidential in nature.
 Under no circumstances is this software to be combined with any Open Source
 Software in any way or placed under an Open Source License of any type without
 the express written permission of Koninklijke Philips N.V.
*******************************************************************************/

#ifndef __FSM_H__
#define __FSM_H__

#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* INCLUDE FILES
*******************************************************************************/
#include "typedefs.h"

/*******************************************************************************
* CONSTANTS
*******************************************************************************/
#define     ALL_STATES      (0xFF)
#define     SAME_STATE      (0xFF)
#define     FSM_NAME_LEN    (32)

/*******************************************************************************
* MACROS
*******************************************************************************/

/*******************************************************************************
* TYPEDEFS
*******************************************************************************/
typedef uint8   const (*condition)(void);
typedef void    const (*action)(void);

typedef struct _fsm_table_t
{
    uint8       current_state;
    uint8       event;
    condition   condition_func;
    action      action_func;
    uint8       next_state;
} fsm_table_t;
  
typedef struct
{
    uint8  state;
    char   name[FSM_NAME_LEN];
} fsm_sate_name_t;

typedef struct 
{
    uint8               current_state;
    uint8               module_id;
    CODE fsm_table_t    *p_table;
    uint8               table_size;
} fsm_handle_t;


/*******************************************************************************
* VARIABLES
*******************************************************************************/

/*******************************************************************************
* FUNCTIONS
*******************************************************************************/
void fsm_init(void);
//
//  function    :   This function inits the FSM system
//  pre         :   -
//  post        :   All variables for the FSM system have been initialised
//

uint8  fsm_evaluate(uint8 module_id, uint8 event);
//
//  function    :   This function evaluates StateMachine module_id with 
//                     event
//  pre         :   The FSM system has been initialised   
//  post        :   The function returns TRUE when the event has been 
//                  succesfully handled. When an active state doesn't 
//                  handle this event FALSE is returned
//


uint8  fsm_create(
    fsm_handle_t        *p_fsm_handle,
    uint8               module_id,
    uint8               init_state,
    CODE fsm_table_t    *p_table,
    uint8               table_size
);
//
//  function    :   This function declares and initializes a FSM structure 
//  pre         :   -   
//  post        :   The FSM table is initialized for this module
//


#ifdef __cplusplus
}
#endif

#endif //__FSM_H__

/******************************************************************************/

